<template>
  <base-layout
     :dialog-title="dialogTitle"
    :dialog-visible="dialogVisible"
    dialog-width="600px"
    :page-show="pageShow"
    @dialog-close="dialogClose"
  >
    <template #toolPanel />
    <template #searchPanel>
      <search-panel :show-add-button="false" :show-search-button="true" labelWidth="73" @search="search" :left="true">
        <el-form-item label="分销商:">
          <el-select v-model="filters.downId" clearable>
            <el-option
              v-for="item in downUsers"
              :key="item.user.useruuid"
              :label="item.user.username"
              :value="item.user.useruuid"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="供货商:">
          <el-select v-model="filters.upId" clearable>
            <el-option
              v-for="item in upUsers"
              :key="item.user.useruuid"
              :label="item.user.username"
              :value="item.user.useruuid"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="开始时间:">
          <el-date-picker type="datetime" placeholder="开始时间"  format="yyyy-MM-dd HH:mm:ss" clearable  v-model="filters.startTime" style="width: 100%;"></el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间:">
          <el-date-picker type="datetime" placeholder="结束时间" clearable format="yyyy-MM-dd HH:mm:ss"   v-model="filters.endTime" style="width: 100%;"></el-date-picker>
        </el-form-item>
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="false"
        :current="start"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
        <template #action="{row}">
<!--          <el-button type="text" @click="dialogVisible = true">编辑</el-button>-->
<!--          <el-button type="text" style="color:red;" @click="deletedRow(row)">删除</el-button>-->
        </template>
      </data-table>
    </template>

    <template #dialog>
<!--      <dialog-data-form :value="dialogData"  @operate="handleDataOperate"/>-->
    </template>

  </base-layout>
</template>

<script>
import baseMixin from '@/mixins/base'
import moment from "moment";
import { getProductDiscount,findAllDownShopInfo,findAllUpShopInfo } from '@/api/utilsapi'

export default {
  name: 'discount',
  components: {  },
  mixins: [
    baseMixin({
      idName: 'id',
      findData: getProductDiscount,
      refresh: '',
      format(res) {
        return res.map(data => {
          return data
        })
      }
    })
  ],
  data() {
    return {
      buttons: [],
      pageShow: true,
      dialogData:{},
      tableColumnAttributes: [
        { name: '分销渠道', value: 'username'},
        { name: '分销面值', value: 'downfacevalue' },
        { name: '分销折扣', value: 'discountDown' },
        { name: '供货渠道', value: 'upname' },
        { name: '供货折扣', value: 'discountUp' }
      ],
      filters: {
        startTime: moment().subtract('hour', 3).format('YYYY-MM-DD HH:mm:ss') ,
        endTime: moment(new Date(),"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD') + " 23:59:59",
        upId:'',
        downId:'',
      },
      downUsers:[],
      upUsers:[]
    }
  },
  methods: {
    search(form){
      let para = {
        start: 0,
        pageSize: 10,
        startTime:this.filters.startTime == undefined ? "" : this.filters.startTime,
        endTime:this.filters.endTime == undefined ? "" : this.filters.endTime,
        upId:this.filters.upId,
        downId:this.filters.downId,
      };
      this.searchOptions = para;
      this.setTableData()
    },
    async findAllDownShopInfo(){
      let para = {useruuid: this.$store.getters.useruuid};
      const result = await findAllDownShopInfo(para);
      if(result && result.data){
        this.downUsers = result.data;
      }
    },
    async findAllUpShopInfo(){
      let para = {
        test:''
      };
      findAllUpShopInfo(para).then(datas =>{
        let {message, code, data} = datas;
        if (code !== "0") {
          this.$message({
            message: message,
            type: 'error'
          });
        } else {
          this.upUsers = data;
        }
      });
    },
  },
  mounted() {
    this.findAllUpShopInfo();
    this.findAllDownShopInfo();
  }
}
</script>
